package cn.tuling.v1;

/**
 * 缺点：
 * 1. 封装性差：高层模块需要负责Boy类的备份与恢复，这应该是Boy类的职责
 */
public class MementoTest {
    public static void main(String[] args) {
        Boy boy = new Boy();
        boy.setState("I‘m so good good.");
        System.out.println("初始状态");
        System.out.println(boy.getState());

        Boy backup = new Boy();
        backup.setState(boy.getState());

        System.out.println("改变状态");
        boy.changeState();
        System.out.println(boy.getState());

        System.out.println("恢复状态");
        boy.setState(backup.getState());
        System.out.println(boy.getState());
    }
}

class Boy {
    private String state;

    public void changeState() {
        this.state = "You so bad bad.";
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }
}